package com.sinaweibo.util;

import java.util.List;

import org.apache.log4j.Logger;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * desc:
 * <p>
 * Copyright: Copyright(c)Gb 2011
 * </p>
 * 
 * @author <a href="mailTo:jeson.sha@goodbabygroup.com">jeson.sha</a>
 * @time 2011-11-18 上午08:54:09
 * @version 1.0
 * @since
 */
public class Log4jUtil {
	public static void info(String sql, Object[] params, Logger log) {
		if (log.isInfoEnabled()) {
			StringBuffer sb = new StringBuffer(sql).append(" ").append(
					" params:");
			for (int i = 0; i < params.length; i++) {
				sb.append(params[i]);
				if (i < params.length) {
					sb.append(",");
				}
			}
			log.info(sb);
		}
	}

	public static String getInfo(String sql, Object[] params) {
		StringBuffer sb = new StringBuffer(sql).append(" ").append(" params:");
		for (int i = 0; i < params.length; i++) {
			sb.append(params[i]);
			if (i < params.length) {
				sb.append(",");
			}
		}
		return sb.toString();
	}

	public static String getInfoForObject(String sql, Object... params) {
		StringBuffer sb = new StringBuffer(sql).append(" ").append(" params:");
		for (int i = 0; i < params.length; i++) {
			sb.append(params[i]);
			if (i < params.length) {
				sb.append(",");
			}
		}
		return sb.toString();
	}

	public static void info(String sql, List<Object> params, Logger log) {
		info(sql, params.toArray(), log);
	}
}
